package com.gaobug.base.config.mq;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * rabbitmq加载配置文件
 *
 * @author hzq
 * @date 2022/3/24 11:27
 */
@Getter
@Setter
@ToString
@ConfigurationProperties(prefix = RabbitMqProperties.PREFIX)
public class RabbitMqProperties {
    public final static String PREFIX = "gaobug.rabbitmq";
    /**
     * rabbitMQ服务器的地址
     */
    private String addresses;
    /**
     * rabbitMQ用户名
     */
    private String username;
    /**
     * rabbitMQ密码
     */
    private String password;
    /**
     * rabbitMQ虚拟机
     */
    private String virtualHost = "/";
    /**
     * 开启rabbitMQ
     */
    private boolean enable;
    /**
     * 队列列表
     */
    private Map<String, QueueConfig> queueConfig;

    public static class QueueConfig {
        private String queueName;
        private String exchangeName;
        private String deadExchangeName;
        private String exchangeType;
        private Boolean isDurable = true;
        private Boolean isExclusive = false;
        private Boolean isAutoDelete = false;

        /**
         * 获取队列名称
         *
         * @return 队列名称
         */
        public String getQueueName() {
            return queueName;
        }

        /**
         * 获取交换机名称
         *
         * @return 交换机名称
         */
        public String getExchangeName() {
            return exchangeName;
        }

        /**
         * 获取附带的死信队列交换机名称
         *
         * @return 死信队列交换机名称
         */
        public String getDeadExchangeName() {
            return deadExchangeName;
        }

        /**
         * 获取交换机类型
         *
         * @return 交换机类型
         * @see org.springframework.amqp.core.ExchangeTypes;
         */
        public String getExchangeType() {
            return exchangeType;
        }

        /**
         * A durable queue will survive a server restart.
         *
         * @return true if durable.
         */
        public boolean isDurable() {
            return isDurable;
        }

        /**
         * True if the server should only send messages to the declarer's connection.
         *
         * @return true if exclusive.
         */
        public boolean isExclusive() {
            return isExclusive;
        }

        /**
         * True if the server should delete the queue when it is no longer in use (the last consumer is cancelled). A queue
         * that never has any consumers will not be deleted automatically.
         *
         * @return true if auto-delete.
         */
        public boolean isAutoDelete() {
            return isAutoDelete;
        }

        public void setQueueName(String queueName) {
            this.queueName = queueName;
        }

        public void setExchangeName(String exchangeName) {
            this.exchangeName = exchangeName;
        }

        public void setDeadExchangeName(String deadExchangeName) {
            this.deadExchangeName = deadExchangeName;
        }

        public void setExchangeType(String exchangeType) {
            this.exchangeType = exchangeType;
        }

        public void setDurable(boolean durable) {
            isDurable = durable;
        }

        public void setExclusive(boolean exclusive) {
            isExclusive = exclusive;
        }

        public void setAutoDelete(boolean autoDelete) {
            isAutoDelete = autoDelete;
        }
    }
}
